<%@ page language="java" import="java.util.*" pageEncoding="utf-8" %>
<%@include file="/commons/taglibs.jsp" %>
<!DOCTYPE html>
<html>
<fmt:bundle basename="res">
<head>
    <meta charset="utf-8">
    <title><fmt:message key='lb' /></title>
    <jsp:include page="/WEB-INF/commons/commons-header.jsp" flush="true"/>
</head>
<body>

<div class="layui-fluid">
    <div class="layui-card">
        <div class="layui-form layui-card-header layuiadmin-card-header-auto">

            <div class="layui-form-item">
                <form name="totalForm" id="totalForm" action="${web_domain}/supplier/goods/attribute/list" method="get">

                    <div class="layui-inline">
                        <label class="layui-form-label"><fmt:message key='ggmc' /></label>
                        <div class="layui-input-inline">
                            <input type="text" name="name" placeholder="<fmt:message key='qsrggmc' />" value="<c:if test='${params.name !=null}'>${params.name}</c:if>" autocomplete="off" class="layui-input">
                        </div>
                    </div>

                    <div class="layui-inline">
                        <label class="layui-form-label"><fmt:message key='zt' /></label>
                        <div class="layui-input-inline">
                            <select name="status">
                                <option value="0"><fmt:message key='qxz' /></option>
                                <option value="1"><fmt:message key='qy' /></option>
                                <option value="2"><fmt:message key='jy' /></option>
                            </select>
                        </div>
                    </div>

                    <div class="layui-inline">
                        <button class="layui-btn layui-btn-sm layuiadmin-btn-list" id="search"><i class="layui-icon layui-icon-search layuiadmin-button-btn"></i> <fmt:message key='ss' /></button>
                    </div>
                </form>
            </div>
        </div>

    </div>

    <div class="layui-card">
        <div class="layui-field-box layui-form">
            <a href="javascript:void(0);" class="layui-btn layui-btn-sm layui-btn-normal" id="add"><i class="layui-icon">&#xe61f;</i> <fmt:message key='tjgg' /></a>

            <div class="layui-tab layui-tab-brief" lay-filter="docDemoTabBrief">
                <ul class="layui-tab-title">
                    <li
                            <c:if test="${params.type eq 0}">class="layui-this"</c:if> >
                        <a href="${web_domain}/supplier/goods/attribute/list"
                           <c:if test="${params.type eq 0}">style="color: rgb(0, 150, 136)"</c:if> ><fmt:message key='zj' /></a>
                    </li>
                    <li <c:if test="${params.type eq 1}">class="layui-this"</c:if>>
                        <a href="${web_domain}/supplier/goods/attribute/list?type=1" <c:if test="${params.type eq 1}">style="color: rgb(0, 150, 136)"</c:if>><fmt:message key='pt' /></a>
                    </li>

                </ul>
            </div>

            <table class="layui-table" lay-size="sm">
                <thead>
                <th width="5%"><fmt:message key='xh' /></th>
                <th width="15%"><fmt:message key='ggmc' /></th>
                <th width="10%"><fmt:message key='ggms' /></th>
                <th width="60%"><fmt:message key='ggsx' /></th>
                <c:if test="${params.type eq 0}">
                    <th width="10%"><fmt:message key='cz' /></th>
                </c:if>

                </thead>
                <c:forEach items="${page.result}" var="item" varStatus="status">
                    <tr>
                        <td>${status.index + 1 }</td>
                        <td>${item.name }</td>
                        <td>${item.note }</td>
                        <td><c:forEach items="${item.attributes}" var="i"> [ ${i.name} ] </c:forEach></td>
                        <c:if test="${params.type eq 0}">
                            <td>
                                <div class="layui-btn-container">
                                    <c:if test="${params.type != 1}">

                                        <a href="javascript:void(0);" data-id="${item.id}" class="layui-btn layui-btn-xs feijin-modify"><fmt:message key='bj' /></a>
                                        <c:choose>
                                            <c:when test="${item.status eq 1}">
                                                <a href="javascript:void(0);" data-id="${item.id}" class="layui-btn layui-btn-danger layui-btn-xs feijin-disable"><fmt:message key='jy' /></a>
                                            </c:when>
                                            <c:otherwise>
                                                <a href="javascript:void(0);" data-id="${item.id}" class="layui-btn layui-btn-xs feijin-enable"><fmt:message key='qy' /></a>
                                                <a href="javascript:void(0);" data-id="${item.id}" class="layui-btn layui-btn-danger layui-btn-xs feijin-remove"><fmt:message key='sc' /></a>
                                            </c:otherwise>
                                        </c:choose>
                                    </c:if>
                                </div>
                            </td>
                        </c:if>
                    </tr>
                </c:forEach>
            </table>
            <jsp:include page="/commons/page.jsp" flush="true"/>
        </div>
    </div>

</div>

<script>

    $(function () {

        //添加用户
        $("#add").click(function () {
            layer.open({
                type: 2
                , title: '<fmt:message key='tjgg' />'
                , content: '${web_domain}/supplier/goods/attribute/create'
                , maxmin: true
                , area: ['80%', '80%']
                , btn: ['<fmt:message key='qd' />', '<fmt:message key='qx' />']
                , yes: function (index, layero) {
                    var submit = layero.find('iframe').contents().find("#submit");
                    submit.click();
                }
            });
        });

        //编辑
        $(".feijin-modify").click(function () {

            var id = $(this).attr("data-id");

            layer.open({
                type: 2
                , title: '<fmt:message key='bjgg' />'
                , content: '${web_domain}/supplier/goods/attribute/' + id + '/modify'
                , maxmin: true
                , area: ['80%', '80%']
                , btn: ['<fmt:message key='qd' />', '<fmt:message key='qx' />']
                , yes: function (index, layero) {
                    var submit = layero.find('iframe').contents().find("#submit");
                    submit.click();
                }
            });
        });

        //启用规格
        $(".feijin-enable").click(function () {
            var id = $(this).attr("data-id");
            layui.use('layer', function () {
                var layer = layui.layer;
                layer.open({
                    type: 0,
                    title: '<fmt:message key='qygg' />',
                    border: [0],
                    content: '<span class="orange"><fmt:message key='qdqygggm' /></span>',
                    btn: ['<fmt:message key='qy' />', '<fmt:message key='qx' />'],
                    yes: function () {
                        $.ajax({
                            type: "post",
                            url: "${web_domain}/supplier/goods/attribute/enable",
                            dataType: "json",
                            data: {
                                "id": id,
                                "_method": "put"
                            },
                            success: function (data) {
                                if (data.status) {
                                    location.reload();
                                } else {
                                    layui.use('layer', function () {
                                        layer.msg(data.message);
                                    });
                                }

                            }
                        });
                    },
                    no: function () {
                        layer.close(index);
                    }
                });
            });

        });

        //禁用规格
        $(".feijin-disable").click(function () {
            var id = $(this).attr("data-id");
            layui.use('layer', function () {
                var layer = layui.layer;
                layer.open({
                    type: 0,
                    title: '<fmt:message key='jygg' />',
                    border: [0],
                    content: '<span class="orange"><fmt:message key='qdjygggm' /></span>',
                    btn: ['<fmt:message key='jy' />', '<fmt:message key='qx' />'],
                    yes: function () {
                        $.ajax({
                            type: "post",
                            url: "${web_domain}/supplier/goods/attribute/disable",
                            dataType: "json",
                            data: {
                                "id": id,
                                "_method": "put"
                            },
                            success: function (data) {
                                if (data.status) {
                                    location.reload();
                                } else {
                                    layui.use('layer', function () {
                                        layer.msg(data.message);
                                    });
                                }

                            }
                        });
                    },
                    no: function () {
                        layer.close(index);
                    }
                });
            });

        });

        //删除规格
        $(".feijin-remove").click(function () {
            var id = $(this).attr("data-id");
            layui.use('layer', function () {
                var layer = layui.layer;
                layer.open({
                    type: 0,
                    title: '<fmt:message key='scgg' />',
                    border: [0],
                    content: '<span class="orange"><fmt:message key='qdscgg' /></span>',
                    btn: ['<fmt:message key='sc' />', '<fmt:message key='qx' />'],
                    yes: function () {
                        $.ajax({
                            type: "post",
                            url: "${web_domain}/supplier/goods/attribute/remove",
                            dataType: "json",
                            data: {
                                "id": id,
                                "_method": "delete"
                            },
                            success: function (data) {
                                if (data.status) {
                                    location.reload();
                                } else {
                                    layui.use('layer', function () {
                                        layer.msg(data.message);
                                    });
                                }

                            }
                        });
                    },
                    no: function () {
                        layer.close(index);
                    }
                });
            });
        });


    });
</script>
</body>
</fmt:bundle>
</html>
